| Conditions | 1 |
| Paths | 8 |
| Total Lines | 56 |
| Lines | 27 |
| Ratio | 48.21 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import path from 'path' |
||
| 141 | var p = new Promise((resolve, reject) => { |
||
| 142 | var p1 = new Promise((resolve) => { |
||
| 143 | cmsOperations.save.save( |
||
| 144 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 145 | tplPath, |
||
| 146 | json, |
||
| 147 | '', |
||
| 148 | 'draft', |
||
| 149 | null, |
||
| 150 | 'reject') |
||
| 151 | .then((resSave) => { |
||
| 152 | resolve() |
||
| 153 | }).catch(function(e) { |
||
| 154 | console.error(e) |
||
| 155 | }) |
||
| 156 | }) |
||
| 157 | |||
| 158 | p1.then((resSave) => { |
||
| 159 | cmsOperations.save.save( |
||
| 160 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 161 | tplPath, |
||
| 162 | json, |
||
| 163 | '', |
||
| 164 | 'reject', |
||
| 165 | resSave, |
||
| 166 | 'reject') |
||
| 167 | .then((resSave) => { |
||
| 168 | var result |
||
| 169 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 170 | result = { |
||
| 171 | success: 0, |
||
| 172 | error: resSave.error |
||
| 173 | } |
||
| 174 | } else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 175 | resSave.success = 1 |
||
| 176 | result = resSave |
||
| 177 | } else if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 178 | result = { |
||
| 179 | success: 1, |
||
| 180 | json: resSave.json |
||
| 181 | } |
||
| 182 | } |
||
| 183 | abeExtend.hooks.instance.trigger('afterReject', result) |
||
| 184 | Manager.instance.updateList() |
||
| 185 | resolve(result) |
||
| 186 | }) |
||
| 187 | }).catch(function(e) { |
||
| 188 | console.error(e) |
||
| 189 | var result = { |
||
| 190 | success: 0, |
||
| 191 | error: 'reject error' |
||
| 192 | } |
||
| 193 | abeExtend.hooks.instance.trigger('afterReject', result) |
||
| 194 | resolve(result) |
||
| 195 | }) |
||
| 196 | }) |
||
| 197 | |||
| 199 | } |